{-# LANGUAGE OverloadedStrings #-}
import Test.Framework (defaultMain, testGroup)
import Test.Framework.Providers.HUnit
--import Test.Framework.Providers.QuickCheck (testProperty)

import Test.HUnit

import Data.List
import Data.ByteString (ByteString)
import TNET

main = defaultMain tests

tests = [
        testGroup "Unit Tests" [
            testCase "null" test_null,
            testCase "integer" test_integer,
            testCase "float" test_float,
            testCase "bool" test_bool,
            testCase "empty-bytes" test_empty_bytes,
            testCase "string" test_string,
            testCase "empty-string" test_empty_string,
            testCase "unicode" test_unicode,
            testCase "empty-array" test_empty_array,
            testCase "array" test_array,
            testCase "array-of-null" test_array_of_null,
            testCase "array2" test_array2,
            testCase "empty-dict" test_empty_dict,
            testCase "dict1" test_dict1,
            testCase "dict2" test_dict2,
            testCase "dict-of-array" test_dict_of_array,
            testCase "array-of-dict" test_array_of_dict,
            testCase "array-of-array" test_array_of_array,
            testCase "array-of-singleton-array" test_array_of_singleton_array,
            testCase "dict-of-dict" test_dict_of_dict
          ]
  ]

type TDict = [(String, Integer)]

test_null =
  (decode "0:~" :: Maybe ())
  @?= Just ()
test_integer =
  (decode "1:4#" :: Maybe Integer)
  @?= Just 4
test_float =
  (decode "8:5.900000^" :: Maybe Double)
  @?= Just 5.9
test_bool =
  (decode "1:t?" :: Maybe Bool)
  @?= Just True
test_empty_bytes =
  (decode "0:," :: Maybe ByteString)
  @?= Just ""
test_string =
  (decode "5:hello$" :: Maybe String)
  @?= Just "hello"
test_empty_string =
  (decode "0:$" :: Maybe String)
  @?= Just ""
test_unicode =
  (decode "7:mu = \194\181$" :: Maybe String)
  @?= Just "mu = µ"
test_empty_array =
  (decode "0:]" :: Maybe [()])
  @?= Just []
test_array =
  (decode "4:1:1#]" :: Maybe [Integer])
  @?= Just [1]
test_array_of_null =
  (decode "3:0:~]" :: Maybe [()])
  @?= Just [()]
test_array2 =
  (decode "8:1:1#1:2#]" :: Maybe [Integer])
  @?= Just [1,2]
test_empty_dict =
  (decode "0:}" :: Maybe TDict)
  @?= Just []
test_dict1 =
  (decode "8:1:a$1:1#}" :: Maybe TDict)
  @?= Just [("a", 1)]
test_dict2 =
  (decode "16:1:a$1:1#1:b$1:2#}" :: Maybe TDict)
  @?= Just [("a", 1), ("b", 2)]
test_dict_of_array =
  (decode "20:1:a$12:1:1#1:2#1:3#]}" :: Maybe [(String, [Integer])])
  @?= Just [("a", [1,2,3])]
test_array_of_dict =
  (decode "31:8:1:a$1:1#}16:1:a$1:2#1:b$1:3#}]" :: Maybe [TDict])
  @?= Just [[("a",1)],[("a",2),("b",3)]]
test_array_of_array =
  (decode "27:8:1:1#1:2#]12:1:3#1:4#1:5#]]" :: Maybe [[Integer]])
  @?= Just [[1,2],[3,4,5]]
test_array_of_singleton_array =
  (decode "14:4:1:7#]4:1:8#]]" :: Maybe [[Integer]])
  @?= Just [[7],[8]]
test_dict_of_dict =
  (decode "24:1:a$16:1:b$1:2#1:c$1:3#}}" :: Maybe [(String, TDict)])
  @?= Just [("a", [("b", 2), ("c", 3)])]
